import { defineStore } from 'pinia';
import { NotificationItem } from '@/interface';
import { t } from '@wangeditor/core';
import { getListByPageAPI } from '@/api/wedding/noticeInfo';
import { ElMessage } from "element-plus";

const msgData = [
  {
    id: '123',
    notice: '腾讯大厦一楼改造施工项目 已通过审核！',
    type: '合同动态',
    status: "1",
    createTime: '2025-07-22 08:00:00',
    quality: 'high',
  },
  {
    id: '124',
    notice: '三季度生产原材料采购项目 开票成功！',
    type: '票务动态',
    status: "1",
    createTime: '2021-01-01 08:00:00',
    quality: 'low',
  },
  {
    id: '125',
    notice: '2021-01-01 10:00的【国家电网线下签约】会议即将开始，请提前10分钟前往 会议室1 进行签到！',
    type: '会议通知',
    status: "0",
    createTime: '2021-01-01 08:00:00',
    quality: 'middle',
  },
  {
    id: '126',
    notice: '一季度生产原材料采购项目 开票成功！',
    type: '票务动态',
    status: "0",
    createTime: '2021-01-01 08:00:00',
    quality: 'low',
  },
  {
    id: '127',
    notice: '二季度生产原材料采购项目 开票成功！',
    type: '票务动态',
    status: "0",
    createTime: '2021-01-01 08:00:00',
    quality: 'low',
  },
  {
    id: '128',
    notice: '三季度生产原材料采购项目 开票成功！',
    type: '票务动态',
    status: "0",
    createTime: '2021-01-01 08:00:00',
    quality: 'low',
  },
];

type MsgDataType = typeof msgData;


export const useNotificationStore = defineStore('notification', {
  state: () => ({
    msgData,
  }),
  getters: {
    unreadMsg: (state) => state.msgData.filter((item: NotificationItem) => item.status == '0'),
    readMsg: (state) => state.msgData.filter((item: NotificationItem) => item.status == '1'),
  },
  actions: {
    setMsgData(data: MsgDataType) {
      this.msgData = data;
    },
    async getMsgData() {
      let params = {
        current: 1,
        pageSize: 9999999,
      };
      try {
        const res = await getListByPageAPI(params);
        if (res.code === 0) {
          this.setMsgData(res.data.list);
        } else {
          ElMessage({
            type: "error",
            message: "获取消息数据失败",
          });
        }
      } catch (error) {
        ElMessage({
          type: "error",
          message: "获取消息数据失败",
        });
      }
    },
  },
});
